//
//  ZMYNetWorkAPI.m
//  奇阅
//
//  Created by 奇阅科技 on 14-10-20.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "ZMYNetWorkAPI.h"
//#include <sys/socket.h> // Per msqr
//#include <sys/sysctl.h>
//#include <net/if.h>
//#include <net/if_dl.h>
#import "Config.h"
#import "TaskList.h"
#import "BookChapterText.h"
@interface ZMYNetWorkAPI ()
@property (strong, nonatomic) NSMutableArray *downloadPermissionArray;
@property (strong, nonatomic) NSMutableArray *downloadChargeArray;
@property (strong, nonatomic) MKNetworkEngine *engineNotToken;
@property (strong, nonatomic) MKNetworkEngine *engineYiDong;
@property (strong, nonatomic) MKNetworkEngine *engineYiDongChapter;
@end
@implementation ZMYNetWorkAPI
-(void)dealloc{
    NSLog(@"ZMYNetWorkAPI网络库释放了");
}
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil||jsonString.length<1) {
        return nil;
    }
    jsonString = [[[[[[[[jsonString stringByReplacingOccurrencesOfString:@"	" withString:@""]stringByReplacingOccurrencesOfString:@"<br/>" withString:@"\\n"]stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\'"]stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@" "]stringByReplacingOccurrencesOfString:@"<p>" withString:@""]stringByReplacingOccurrencesOfString:@"</p>" withString:@"\\n"]stringByReplacingOccurrencesOfString:@"<span>" withString:@"    "]stringByReplacingOccurrencesOfString:@"</span>" withString:@""];
    
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:0
                                                          error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}
///获取当前时间戳
+ (NSTimeInterval)currentTime
{
    NSDate *date = [NSDate date];
    NSTimeInterval aInterval =[date timeIntervalSince1970];
    return aInterval;
}

- (BOOL)detectionFormDict:(NSDictionary*)dict withURL:(NSString *)url
{
    //检测是否有NSNull类型
    NSArray *keys = [dict allKeys];
    for (NSString *key in keys) {
        if ([[dict objectForKey:key] isKindOfClass:[NSNull class]]) {
            NSLog(@"----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------网络数据发现NSNull类型,URL:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n%@",url);
            return NO;
        }else if ([[dict objectForKey:key] isKindOfClass:[NSDictionary class]]) {
            id obj = [dict objectForKey:key];
            if (![self detectionFormDict:obj withURL:url]) {
                return NO;
            }
        }else if ([[dict objectForKey:key] isKindOfClass:[NSArray class]]){
            for (id obj in [dict objectForKey:key]) {
                if ([obj isKindOfClass:[NSNull class]]) {
                    NSLog(@"网络数据发现NSNull类型,URL:%@",url);
                    return NO;
                }else if ([obj isKindOfClass:[NSDictionary class]]){
                    if (![self detectionFormDict:obj withURL:url]) {
                        return NO;
                    }
                }
            }
        }
    }
    return YES;
}
+(ZMYNetWorkAPI *)default{
    static ZMYNetWorkAPI *api;
    @synchronized(self){
        if(!api){
            api=[[ZMYNetWorkAPI alloc]init];
        }
    }
    return api;
}
///初始化无token引擎
-(MKNetworkEngine *)createEngine{
    @synchronized(self) {
        if (self.engineNotToken==nil) {
            _engineNotToken= [[MKNetworkEngine alloc] initWithHostName:[NSString stringWithFormat: @"%@",SERVER]];
        }
    }
    return self.engineNotToken;
}
///初始化移动基地无token引擎
-(MKNetworkEngine *)createEngineYiDong{
    @synchronized(self) {
        if (self.engineYiDong==nil) {
            _engineYiDong= [[MKNetworkEngine alloc] initWithHostName:[NSString stringWithFormat: @"%@",YiDongSERVER]];
        }
    }
    return self.engineYiDong;
}
///初始化移动基地章节下载引擎
-(MKNetworkEngine *)createEngineYiDongChapter{
    @synchronized(self) {
        if (self.engineYiDongChapter==nil) {
            _engineYiDongChapter= [[MKNetworkEngine alloc] initWithHostName:[NSString stringWithFormat: @"%@",YiDongChapterSERVER]];
        }
    }
    return self.engineYiDongChapter;
}
///移动基地链接
-(void)yiDongConnect:(NSDictionary *)param url:(NSString *)path response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    MKNetworkOperation *op = [[self createEngineYiDong] operationWithPath:path params:param httpMethod:@"GET"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        id result =[completedOperation responseJSON];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
                resultDict(result);
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
    }];
    [[self createEngine] enqueueOperation:op forceReload:YES];
}
///移动基地链接
-(void)yiDongChapterConnect:(NSDictionary *)param url:(NSString *)path response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    MKNetworkOperation *op = [[self createEngineYiDongChapter] operationWithPath:path params:param httpMethod:@"GET"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        id result =[self dictionaryWithJsonString:[completedOperation responseString]];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
                resultDict(result);
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
    }];
    [[self createEngine] enqueueOperation:op forceReload:YES];
}
-(void)noTokenGetConnect:(NSDictionary *)param url:(NSString *)path response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    MKNetworkOperation *op = [[self createEngine] operationWithPath:path params:param httpMethod:@"GET"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        id result =[completedOperation responseJSON];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
                if ([[result objectForKey:@"ret"] isEqualToString:@"200"]) {
                    resultDict(result);
                }else{
                    errorString([result objectForKey:@"msg"]);
                }
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
    }];
    [[self createEngine] enqueueOperation:op forceReload:YES];
}
-(void)noTokenPostConnect:(NSDictionary *)param url:(NSString *)path response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    MKNetworkOperation *op = [[self createEngine] operationWithPath:path params:param httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        id result =[completedOperation responseJSON];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
                if ([[result objectForKey:@"ret"] isEqualToString:@"200"]) {
                    resultDict(result);
                }else{
                    errorString([result objectForKey:@"msg"]);
                }
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        NSLog(@"%@",error.localizedDescription);
        errorString(@"网络连接失败!");
    }];
    [[self createEngine] enqueueOperation:op forceReload:YES];
}
#pragma mark - 意见反馈
-(void)feedback:(NSString *)textStr response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObject:textStr forKey:@"contents"];
    MKNetworkOperation *op = [[self createEngine] operationWithPath:@"web/qy_about.php?a=feedback" params:params httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        id result =[completedOperation responseJSON];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
            if ([[result objectForKey:@"ret"] isEqualToString:@"200"]) {
                resultDict([result objectForKey:@"body"]);
            }else{
                errorString([result objectForKey:@"msg"]);
            }
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
    }];
    [[self createEngine] enqueueOperation:op forceReload:YES];
}
#pragma mark - 发送手机短信验证码
-(void)smsLogin:(NSString *)mobile response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"post_sms_code" forKey:@"a"];
    [param setObject:mobile forKey:@"mobile"];
    [self noTokenGetConnect:param url:@"web/qy_reg.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}

#pragma mark 设置新密码
-(void)smsLoginMobileParam:(NSDictionary *)param response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    [self noTokenGetConnect:param url:@"web/qy_reg.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 老用户登录
-(void)loginUsername:(NSString *)username passwd:(NSString *)passwd response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"qyuser_login" forKey:@"a"];
    [param setObject:username forKey:@"username"];
    [param setObject:[passwd md5] forKey:@"passwdhash"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 第三方登录
-(void)sinaQQLogin:(NSDictionary *)param response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *params = [NSMutableDictionary new];
    if ([[param objectForKey:@"type"] isEqualToString:@"qq"]) {
        [params setObject:@"get_qq_user_info" forKey:@"a"];
        [params setObject:QQAppKey forKey:@"oauth_consumer_key"];
        [params setObject:[param objectForKey:@"openid"] forKey:@"openid"];
        [params setObject:[param objectForKey:@"access_token"] forKey:@"access_token"];
        [params setObject:@"json" forKey:@"format"];
    }else{
        [params setObject:@"get_weibo_user_info" forKey:@"a"];
        [params setObject:[param objectForKey:@"openid"] forKey:@"uid"];
        [params setObject:[param objectForKey:@"access_token"] forKey:@"access_token"];
        [params setObject:@"json" forKey:@"data"];
    }
    
    [self noTokenGetConnect:params url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 忘记密码请求验证短信
-(void)forgetPWgetSMS:(NSString *)mobile response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"forget_userpwd" forKey:@"a"];
    [param setObject:mobile forKey:@"mobile"];
    [self noTokenGetConnect:param url:@"web/qy_reg.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 绑定手机获取短信验证码
-(void)userBindingPhone:(NSString *)mobile response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    //web/qy_reg.php?a=get_mobile_vcode&uid=&token=&mobile=&data=json
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"get_mobile_vcode" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:mobile forKey:@"mobile"];
    [self noTokenGetConnect:param url:@"web/qy_reg.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 绑定手机验证码验证过后
-(void)userBindingPhoneRight:(NSString *)mobile response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    //web/qy_reg.php?a=bind_mobile&uid=&token=&mobile=&data=json
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"bind_mobile" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:mobile forKey:@"mobile"];
    [self noTokenGetConnect:param url:@"web/qy_reg.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 修改昵称
-(void)updateNickName:(NSString *)nickName response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    [param setObject:@"update_nickname" forKey:@"a"];
    [param setObject:nickName forKey:@"new_nickname"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 修改密码
-(void)changePasswd:(NSString *)oldPasswd new:(NSString *)newPasswd response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    [param setObject:@"ch_passwd" forKey:@"a"];
    [param setObject:[oldPasswd md5] forKey:@"oldpasswdhash"];
    [param setObject:[newPasswd md5] forKey:@"newpass"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 积分兑换阅币
-(void)pointsExchangeRemain:(NSUInteger)points Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    ///web/qy_user.php?a=points_for&uid=%s&token=%s&points=%s&ct=android&auth=%s&t=%s
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"points_for" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:[NSNumber numberWithInteger:points] forKey:@"points"];
    [param setObject:@"iOS" forKey:@"srcid"];
    [param setObject:@"json" forKey:@"output"];
    NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
    [param setObject:currentAppVersion forKey:@"v"];
    [param setObject:@"iOS" forKey:@"ct"];
    NSString *time = [NSString stringWithFormat:@"%.f",[ZMYNetWorkAPI currentTime]];
    NSString *auth = [[[NSString stringWithFormat:@"%@%@",[[NSString stringWithFormat:@"%@%@%@",user.uid,time,PRIVATE_KEY] md5],PRIVATE_KEY] md5] substringToIndex:10];
    [param setObject:time forKey:@"t"];
    [param setObject:auth forKey:@"auth"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 修改头像
-(void)updateHeadImage:(UIImage *)image response:(MYResultBlock)resultDict progress:(MYProgressBlock)upProgress error:(MYErrorBlock)errorString{
    NSMutableDictionary *params = [NSMutableDictionary new];
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    [params setObject:user.uid forKey:@"uid"];
    [params setObject:user.token forKey:@"token"];
    NSData *data = UIImageJPEGRepresentation(image, 0.3);
    MKNetworkOperation *op = [[self createEngine] operationWithPath:@"web/qy_user.php?a=post_user_headimg" params:params httpMethod:@"POST"];
    [op addData:data forKey:@"image" mimeType:@"jpg" fileName:@"addBook"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        id result =[completedOperation responseJSON];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
            if ([[result objectForKey:@"ret"] isEqualToString:@"200"]) {
                resultDict([result objectForKey:@"body"]);
            }else{
                errorString([result objectForKey:@"msg"]);
            }
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
    }];
    [op onUploadProgressChanged:^(double progress) {
        NSLog(@"%f",progress);
        upProgress(progress);
    }];
    [op setFreezable:YES];
    [[self createEngine] enqueueOperation:op forceReload:YES];
}

#pragma mark - 获取用户最新信息
-(void)getNewUserInfoResponse:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    [param setObject:@"get_one_userinfo" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        NSDictionary *dict = [resultDic objectForKey:@"body"];
        user.remain = [dict objectForKey:@"remain"];
        user.points = [dict objectForKey:@"integral"];
        user.vip_level = [dict objectForKey:@"rank"];
        user.experience = [dict objectForKey:@"experience"];
        user.is_baoyue = [dict objectForKey:@"is_baoyue"];
        user.needs_experience = [dict objectForKey:@"total_needs_experience"];
        [UserAccount saveAccount:user];
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 获取书籍详情推荐位
-(void)getBookInfoRecommend:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    //dataapi.yuewen.cc/web/store.php?a=recommended
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObject:@"recommended" forKey:@"a"];
    [self noTokenGetConnect:params url:@"web/store.php" response:^(NSDictionary *resultDic) {
        NSArray *bookA = [resultDic objectForKey:@"body"];
        resultArray(bookA);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}

#pragma mark - 获取推荐图书
-(void)getRecommend:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObject:@"get_recommend_book" forKey:@"a"];
    [params setObject:@"1" forKey:@"position"];
    [self noTokenGetConnect:params url:@"web/qy_book.php" response:^(NSDictionary *resultDic) {
        NSArray *bookA = [[resultDic objectForKey:@"body"] objectForKey:@"booklist"];
        NSMutableArray *array = [NSMutableArray new];
        for (NSDictionary *dict in bookA) {
            BookRack *book = [BookRack getFromRecommendDict:dict];
            book.uid = @"love";
            [array addObject:book];
        }
        resultArray(array);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 获取书架接口
-(void)bookRackResultArray:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"get_user_collect_booklist" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        NSArray *bookA = [[resultDic objectForKey:@"body"] objectForKey:@"booklist"];
        NSMutableArray *array = [NSMutableArray new];
        for (NSDictionary *dict in bookA) {
            BookRack *book = [BookRack getFromDict:dict];
            [[ZMYLKDB getLKDBHelper] updateBookRack:book];
            [array addObject:book];
        }
        resultArray(array);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 加入书架
-(void)addBookRackArticleid:(NSString *)articleid response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"synchro_collect" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:articleid forKey:@"add_ids"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 从书架中移除
-(void)removeBookRackArticleid:(NSString *)articleid response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"synchro_collect" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:articleid forKey:@"del_ids"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 已购收藏书评数量
-(void)additionalResponse:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    [param setObject:@"get_user_additional" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 已购收藏列表
-(void)isHadPay:(BOOL)isHadPay page:(NSInteger)page Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    if (isHadPay) {
        [param setObject:@"myvip" forKey:@"a"];
    } else {
        [param setObject:@"get_user_favor_booklist" forKey:@"a"];
    }
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:[NSNumber numberWithInteger:page] forKey:@"page"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 活动信息
-(void)activity:(NSString *)position Response:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    ///dataapi.yuewen.cc/web/store.php?a=announcement&pos=1
    NSMutableDictionary *params = [NSMutableDictionary new];
    [params setObject:@"announcement" forKey:@"a"];
    [params setObject:position forKey:@"pos"];
    [params setObject:@"iOS" forKey:@"ct"];
    UserAccount *user =[UserAccount currentAccount];
    if (user) {
        [params setObject:user.uid forKey:@"uid"];
        [params setObject:user.token forKey:@"token"];
    }
    [self noTokenGetConnect:params url:@"web/store.php" response:^(NSDictionary *resultDic) {
        NSMutableArray *array = [[NSMutableArray alloc]init];
        NSArray *activityList = [resultDic objectForKey:@"body"];
        [[ZMYLKDB getLKDBHelper]clearActivityWithPosition:position];
        for (NSDictionary *dict in activityList) {
            Activity *activ = [Activity getFromDict:dict];
            activ.position = position;
            [[ZMYLKDB getLKDBHelper]updateActivity:activ];
            [array addObject:activ];
        }
        resultArray(array);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}


#pragma mark 获取已订阅的VIP作品
-(void)myVIPPage:(NSInteger)page Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"myvip" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:[NSNumber numberWithInteger:page] forKey:@"page"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        NSArray *bookA = [[resultDic objectForKey:@"body"] objectForKey:@"booklist"];
        if (page == 1) {
            NSInteger DBCount = [[ZMYLKDB getLKDBHelper]getMyVIPBookCount];
            NSInteger count = [[[resultDic objectForKey:@"body"] objectForKey:@"count"] integerValue];
            if (count!=DBCount) {
                [[ZMYLKDB getLKDBHelper]clearMyVIPBook];
            }
        }
        NSMutableArray *array = [NSMutableArray new];
        for (NSDictionary *dict in bookA) {
            MyVIPBook *book = [MyVIPBook getFromDict:dict];
            [[ZMYLKDB getLKDBHelper] updateMyVIPBook:book];
            [array addObject:book];
        }
        resultDict(@{@"booklist":array,@"count":[[resultDic objectForKey:@"body"] objectForKey:@"count"]});
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 获取收藏作品
-(void)myFavorResultArray:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"get_user_favor_booklist" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        NSArray *bookA = [[resultDic objectForKey:@"body"] objectForKey:@"booklist"];
        NSInteger DBCount = [[ZMYLKDB getLKDBHelper]getMyFavorBook].count;
        NSInteger count = [[[resultDic objectForKey:@"body"] objectForKey:@"count"] integerValue];
        if (count!=DBCount) {
            [[ZMYLKDB getLKDBHelper]clearMyFavorBook];
        }
        NSMutableArray *array = [NSMutableArray new];
        for (NSDictionary *dict in bookA) {
            MyFavorBook *book = [MyFavorBook getFromDict:dict];
            [[ZMYLKDB getLKDBHelper] updateMyFavorBook:book];
            [array addObject:book];
        }
        resultArray(array);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 加入收藏
-(void)addMyFavorArticleid:(NSString *)articleid response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    TaskList *taskList = [TaskList currentAccount];
    Task *task = taskList.taskArray[5];
    if (!task.isFinshed) {
        task.isFinshed = YES;
        [TaskList saveAccount:taskList];
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"synchro_myfavor" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:articleid forKey:@"add_ids"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 从收藏中移除
-(void)removeMyFavorArticleid:(NSString *)articleid response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"synchro_myfavor" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:articleid forKey:@"del_ids"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 获取我的书评
-(void)myCommentPage:(NSInteger)page Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"get_user_comments_book" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:[NSNumber numberWithInteger:page] forKey:@"page"];
    [param setObject:@"10" forKey:@"num"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        NSArray *bookA = [[resultDic objectForKey:@"body"] objectForKey:@"commentList"];
        if (page == 1) {
            NSInteger DBCount = [[ZMYLKDB getLKDBHelper]getMyCommentCount];
            NSInteger count = [[[resultDic objectForKey:@"body"] objectForKey:@"count"] integerValue];
            if (count!=DBCount) {
                [[ZMYLKDB getLKDBHelper]clearMyCommentDB];
            }
        }
        NSMutableArray *array = [NSMutableArray new];
        for (NSDictionary *dict in bookA) {
            ThemeComment *comment = [ThemeComment getMyThemeCommentFromDict:dict];
            [[ZMYLKDB getLKDBHelper] updateThemeComment:comment];
            [array addObject:comment];
        }
        resultDict(@{@"commentList":array,@"count":[[resultDic objectForKey:@"body"] objectForKey:@"count"]});
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 获取一本书我的书评
-(void)getMyThemeComment:(Book *)book Page:(NSInteger)page Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"a_user_book_comments" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:book.articleid forKey:@"articleid"];
    [param setObject:[NSNumber numberWithInteger:page] forKey:@"page"];
    [param setObject:@"10" forKey:@"num"];
    [self noTokenGetConnect:param url:@"web/qy_comments.php" response:^(NSDictionary *resultDic) {
        NSArray *bookA = [[resultDic objectForKey:@"body"] objectForKey:@"commentList"];
        if (page == 1) {
            NSInteger DBCount = [[ZMYLKDB getLKDBHelper]getMyCommentCount];
            NSInteger count = [[[resultDic objectForKey:@"body"] objectForKey:@"count"] integerValue];
            if (count!=DBCount) {
                [[ZMYLKDB getLKDBHelper]clearMyCommentDB];
            }
        }
        NSMutableArray *array = [NSMutableArray new];
        for (NSDictionary *dict in bookA) {
            ThemeComment *comment = [ThemeComment getMyThemeCommentFromDict:dict];
            [[ZMYLKDB getLKDBHelper] updateThemeComment:comment];
            [array addObject:comment];
        }
        resultDict(@{@"commentList":array,@"count":[[resultDic objectForKey:@"body"] objectForKey:@"count"]});
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 获取用户充值记录
-(void)getRechargeRecordPage:(NSInteger)page Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    //api.local.com/web/qy_user.php?a=get_user_recharge_record&uid=85623598&token=062dd8cb06&page=1
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"get_user_recharge_record" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:[NSNumber numberWithInteger:page] forKey:@"page"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        NSArray *bookA = [[resultDic objectForKey:@"body"] objectForKey:@"pay_list"];
        NSMutableArray *array = [NSMutableArray new];
        for (NSDictionary *dict in bookA) {
            RechargeRecord *comment = [RechargeRecord new];
            comment.uid = user.uid;
            comment.money = [dict objectForKey:@"money"];
            comment.coin_num = [dict objectForKey:@"coin_num"];
            comment.rechargeRecordID = [dict objectForKey:@"order_sn"];
            NSString *dateStr = [dict objectForKey:@"time"];
            NSString *dateFormatterStr = @"yyyy-MM-dd hh:mm:ss";
            comment.time = [NSString stringWithFormat:@"%.f",[NSString dateStrToDateTimeInterval:dateFormatterStr DateStr:dateStr]];
            comment.isUpdateFinesh = YES;
            [[ZMYLKDB getLKDBHelper] updateRechargeRecord:comment];
            [array addObject:comment];
        }
        resultDict(@{@"pay_list":array,@"count":[[resultDic objectForKey:@"body"] objectForKey:@"count"]});
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 获取作品详情
-(void)getArticle:(NSString *)articleid Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
        NSMutableDictionary *param = [NSMutableDictionary new];
        [param setObject:@"get_article_info" forKey:@"a"];
        [param setObject:articleid forKey:@"articleid"];
        UserAccount *user = [UserAccount currentAccount];
        if (user) {
            [param setObject:user.uid forKey:@"uid"];
            [param setObject:user.token forKey:@"token"];
        }
        [self noTokenGetConnect:param url:@"web/qy_book.php" response:^(NSDictionary *resultDic) {
            NSDictionary *bookDict = [[resultDic objectForKey:@"body"] objectForKey:@"bookinfo"];
            BookInfo *book;
            if ([articleid hasPrefix:@"qiyou"]) {
                book = [BookInfo getFromYiDongDict:bookDict];
            } else {
                book = [BookInfo getFromDict:bookDict];
            }
            [[ZMYLKDB getLKDBHelper]updateBookInfo:book];
            resultDict(bookDict);
        } error:^(NSString *errorStr) {
            errorString(errorStr);
        }];
//    }
    
}

#pragma mark - 获取作品书评
-(void)getThemeComment:(Book *)book commentsid:(NSString *)commentsid Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    if (!commentsid||commentsid.length<1) {
        errorString(@"未找到该条评论，请刷新界面");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"shuping_index" forKey:@"a"];
    [param setObject:book.articleid forKey:@"articleid"];
    [param setObject:commentsid forKey:@"commentsid"];
    [self noTokenGetConnect:param url:@"web/qy_comments.php" response:^(NSDictionary *resultDic) {
        if ([commentsid isEqualToString:@"0"]) {
            [[ZMYLKDB getLKDBHelper]clearThemeCommentDBWith:book.articleid];
        }
        NSArray *hot_comments = [[resultDic objectForKey:@"body"] objectForKey:@"hot_comments"];
        NSMutableArray *hotComment = [[NSMutableArray alloc]initWithCapacity:1];
        for (NSDictionary *hot in hot_comments) {
            ThemeComment *comment = [ThemeComment getFromDict:hot withBook:book];
            [hotComment addObject:comment];
            [[ZMYLKDB getLKDBHelper]updateThemeComment:comment];
        }
        NSArray *commentsList = [[resultDic objectForKey:@"body"] objectForKey:@"commentsList"];
        NSMutableArray *commentList = [[NSMutableArray alloc]initWithCapacity:1];
        for (NSDictionary *comm in commentsList) {
            ThemeComment *comment = [ThemeComment getFromDict:comm  withBook:book];
            [commentList addObject:comment];
            [[ZMYLKDB getLKDBHelper]updateThemeComment:comment];
        }
        resultDict(@{@"hot_comments":hotComment,@"commentsList":commentList,@"count":[[resultDic objectForKey:@"body"] objectForKey:@"count"]});
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}

#pragma mark 获取一条主题书评的回复
-(void)getReplyCommentWithThemeComment:(ThemeComment *)themeComment pageCommentsId:(NSString *)pageCommentsId Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    if (pageCommentsId.length<1||themeComment.commentid.length<1) {
        errorString(@"网络请求错误，请刷新列表再试");
        return;
    }
    
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"one_reply_comments" forKey:@"a"];
    [param setObject:themeComment.articleid forKey:@"articleid"];
    [param setObject:themeComment.commentid forKey:@"replyCommentId"];
    [param setObject:pageCommentsId forKey:@"pageCommentsId"];
    [self noTokenGetConnect:param url:@"web/qy_comments.php" response:^(NSDictionary *resultDic) {
        if ([pageCommentsId isEqualToString:@"0"]) {
            [[ZMYLKDB getLKDBHelper]clearReplyCommentDBWith:themeComment];
        }
        NSArray *commentsList = [[resultDic objectForKey:@"body"] objectForKey:@"commentsList"];
        NSDictionary *theme_commentsDict = [[resultDic objectForKey:@"body"] objectForKey:@"theme_comments"];
        ThemeComment *theme_comments = [ThemeComment getThemeCommentFromDict:theme_commentsDict];
        NSMutableArray *commentList = [[NSMutableArray alloc]initWithCapacity:0];
        for (NSDictionary *comm in commentsList) {
            ReplyComment *comment = [ReplyComment getFromDict:comm withBook:theme_comments.book];
            [commentList addObject:comment];
            [[ZMYLKDB getLKDBHelper]updateReplyComment:comment];
        }
        resultDict(@{@"theme_comments":theme_comments,@"commentsList":commentList,@"count":[[resultDic objectForKey:@"body"] objectForKey:@"count"]});
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 赞一条评论
-(void)likeCommentWithThemeComment:(ThemeComment *)themeComment Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    TaskList *taskList = [TaskList currentAccount];
    Task *task = taskList.taskArray[4];
    if (!task.isFinshed) {
        task.isFinshed = YES;
        [TaskList saveAccount:taskList];
    }
    LikeComment *like = [LikeComment new];
    like.articleid = themeComment.articleid;
    like.commentid = themeComment.commentid;
    if (!user) {
        like.uid = @"love";
    } else {
        like.uid = user.uid;
    }
    
    if ([[ZMYLKDB getLKDBHelper]getIsLikeOnce:like]) {
        if ([[ZMYLKDB getLKDBHelper]getIsLike:like]) {
            like.isLike = NO;
            [[ZMYLKDB getLKDBHelper]updateIsLike:like];
        }else{
            like.isLike = YES;
            [[ZMYLKDB getLKDBHelper]updateIsLike:like];
        }
        return;
    }else{
        like.isLike = YES;
        [[ZMYLKDB getLKDBHelper]updateIsLike:like];
    }
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"point_chan_comments" forKey:@"a"];
    [param setObject:themeComment.articleid forKey:@"articleid"];
    [param setObject:themeComment.commentid forKey:@"replyCommentId"];
    [param setObject:themeComment.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [self noTokenGetConnect:param url:@"web/qy_comments.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 提交主题评论
-(void)commentWithArticleid:(Book *)book content:(NSString *)contents response:(MYResultBlock)resultDict progress:(MYProgressBlock)upProgress error:(MYErrorBlock)errorString{
    [self commentNetworkIsReplyOther:NO Book:book ThemeComment:nil ReplyComment:nil content:contents response:resultDict progress:upProgress error:errorString];
}
#pragma mark 回复主题评论
-(void)commentWithArticleid:(Book *)book ThemeComment:(ThemeComment *)comment ReplyComment:(ReplyComment *)replyComment content:(NSString *)contents response:(MYResultBlock)resultDict progress:(MYProgressBlock)upProgress error:(MYErrorBlock)errorString{
    [self commentNetworkIsReplyOther:YES Book:book ThemeComment:comment ReplyComment:replyComment content:contents response:resultDict progress:upProgress error:errorString];
}
///回复评论
-(void)commentNetworkIsReplyOther:(BOOL)isReply Book:(Book *)book ThemeComment:(ThemeComment *)comment ReplyComment:(ReplyComment *)replyComment content:(NSString *)contents response:(MYResultBlock)resultDict progress:(MYProgressBlock)upProgress error:(MYErrorBlock)errorString{
    NSMutableDictionary *params = [NSMutableDictionary new];
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    if (contents.length>15) {
        TaskList *taskList = [TaskList currentAccount];
        Task *task = taskList.taskArray[0];
        if (!task.isFinshed) {
            task.isFinshed = YES;
            [TaskList saveAccount:taskList];
        }
    }
    [params setObject:user.uid forKey:@"uid"];
    [params setObject:user.token forKey:@"token"];
    [params setObject:book.articleid forKey:@"articleid"];
    [params setObject:contents forKey:@"contents"];
    if (isReply) {
        //如果是回复，主题评论的ID必传
        [params setObject:comment.commentid forKey:@"reply_theme_id"];
        if (replyComment) {
            //如果是回复主题评论的评论，传主题评论的评论的UID和commentid
            [params setObject:replyComment.uid forKey:@"reply_comments_uid"];
            [params setObject:replyComment.commentid forKey:@"replyCommentId"];
        }else{
            //如果是回复主题评论，传主题评论的UID和commentid
//            [params setObject:comment.uid forKey:@"reply_comments_uid"];
            [params setObject:comment.commentid forKey:@"replyCommentId"];
        }
    }
    MKNetworkOperation *op = [[self createEngine] operationWithPath:@"web/qy_comments.php?a=shuping_add_by_ajax" params:params httpMethod:@"POST"];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        id result =[completedOperation responseJSON];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
            if ([[result objectForKey:@"ret"] isEqualToString:@"200"]) {
                if (!isReply) {
                    ThemeComment *comment = [ThemeComment new];
                    comment.uid = user.uid;
                    comment.articleid = book.articleid;
                    comment.book = book;
                    comment.contents = contents;
                    comment.nickName = user.nickname.length>1?user.nickname:user.username;
                    comment.headimg = user.headimg;
                    comment.point_like = @"0";
                    comment.reply_num = @"0";
                    comment.time = [NSString stringWithFormat:@"%.f",[ZMYNetWorkAPI currentTime]];
                    [[ZMYLKDB getLKDBHelper]updateThemeComment:comment];
                }
                resultDict([result objectForKey:@"body"]);
            }else{
                errorString([result objectForKey:@"msg"]);
            }
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
    }];
    [op onUploadProgressChanged:^(double progress) {
        NSLog(@"%f",progress);
        upProgress(progress);
    }];
    [[self createEngine] enqueueOperation:op forceReload:YES];
}
#pragma mark - 书籍阅读
#pragma mark 书本章节列表
-(void)getBookChapterBook:(Book *)book Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    if (!book.articleid) {
        errorString(@"作品ID不能为空");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"index_info" forKey:@"a"];
    [param setObject:book.articleid forKey:@"articleid"];
    [param setObject:@"iOS" forKey:@"srcid"];
    [param setObject:@"iOS" forKey:@"ct"];
    [param setObject:@"json" forKey:@"data"];
    NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];//CFBundleShortVersionString
    [param setObject:currentAppVersion forKey:@"v"];
    
    [self noTokenGetConnect:param url:@"web/qy_book.php" response:^(NSDictionary *resultDic) {
        NSArray *array = [[resultDic objectForKey:@"body"] objectForKey:@"chapter_info"];
        NSMutableArray *chapterArray = [[NSMutableArray alloc]init];
        for (NSDictionary *dict in array) {
            BookChapterInfo *chapter = [BookChapterInfo getFromDict:dict];
            [chapterArray addObject:chapter];
        }
        [NSKeyedArchiver archiveRootObject:chapterArray toFile:[[PathHelper documentDirectoryPathWithName:@"db"]
                                                                stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ChapterInfo",book.articleid]]];
        resultDict([[resultDic objectForKey:@"body"] objectForKey:@"article_info"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 验证书本章节列表是否有更新
-(void)getBookChapterBookHash:(Book *)book Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    if (!book.articleid) {
        errorString(@"作品ID不能为空");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"index_info_hash" forKey:@"a"];
    [param setObject:book.articleid forKey:@"articleid"];
    [param setObject:@"iOS" forKey:@"srcid"];
    [param setObject:@"json" forKey:@"data"];
    NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
    [param setObject:currentAppVersion forKey:@"v"];
    [param setObject:@"iOS" forKey:@"ct"];
    [self noTokenGetConnect:param url:@"web/qy_book.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}

#pragma mark - 书籍下载
#pragma mark 验证章节是否有下载权限
-(void)getDownloadChapterPermission:(NSString *)bookChapters Book:(Book *)book Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    //api.local.com/web/qy_book.php?a=get_download_chapter&uid=85623598&token=062dd8cb06&articleid=159&chapterids=115543,115544,115545,115546,115547&subscription=1&output=josn&pt=
    if (bookChapters.length<1) {
        errorString(@"章节ID不能为空");
        return;
    }
    if (!book.articleid) {
        errorString(@"作品ID不能为空");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"get_download_chapter" forKey:@"a"];
    UserAccount *user = [UserAccount currentAccount];
    if (user) {
        [param setObject:user.uid forKey:@"uid"];
        [param setObject:user.token forKey:@"token"];
    }
    [param setObject:book.articleid forKey:@"articleid"];
    [param setObject:bookChapters forKey:@"chapterids"];
    [param setObject:@"json" forKey:@"output"];
    MKNetworkOperation *op = [[self createEngine] operationWithPath:@"web/qy_book.php" params:param httpMethod:@"GET"];
    if (!self.downloadPermissionArray) {
        _downloadPermissionArray = [[NSMutableArray alloc]init];
    }
    [_downloadPermissionArray addObject:op];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        [self cancelPermissionNetworkOperation:completedOperation];
        id result =[completedOperation responseJSON];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
                resultDict(result);
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
        if (![error.localizedDescription isEqualToString:@"下载任务已取消"]) {
            [self cancelPermissionNetworkOperation:completedOperation];
        }
    }];
    [op setFreezable:YES];
    [[self createEngine] enqueueOperation:op forceReload:YES];

}
#pragma mark 取消一个验证章节是否有下载权限的请求
-(void)cancelPermissionNetworkOperation:(MKNetworkOperation *)completedOperation{
    for (MKNetworkOperation *op in self.downloadPermissionArray) {
        if ([op.url isEqualToString:completedOperation.url]) {
//            [op cancel];
            [self.downloadPermissionArray removeObject:op];
            break;
        }
    }
}
#pragma mark 取消所有验证章节是否有下载权限的请求
-(void)cancelAllPermissionNetworkOperation{
    if (self.downloadPermissionArray) {
        for (MKNetworkOperation *op in self.downloadPermissionArray) {
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"下载任务已取消"                                                                      forKey:NSLocalizedDescriptionKey];
            NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:202 userInfo:userInfo];
            [op operationFailedWithError:error];
            [op cancel];
//            [self.downloadPermissionArray removeObject:op];
        }
    }
    [self.downloadPermissionArray removeAllObjects];
}
#pragma mark 章节扣费接口
-(void)getDownloadChargeForChapters:(NSString *)bookChapters Book:(Book *)book Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    //api.local.com/web/qy_book.php?a=sub_list_texts&chapterids=10000,10001&uid=85623598&token=062dd8cb06&t=1418469883094&auth=4d9f896e84&srcid=
    if (bookChapters.length<1) {
        errorString(@"章节ID不能为空");
        return;
    }
    if (!book.articleid) {
        errorString(@"作品ID不能为空");
        return;
    }
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"sub_list_texts" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:book.articleid forKey:@"articleid"];
    [param setObject:bookChapters forKey:@"chapterids"];
    [param setObject:@"iOS" forKey:@"srcid"];
    NSString *time = [NSString stringWithFormat:@"%.f",[ZMYNetWorkAPI currentTime]];
    NSString *auth = [[[NSString stringWithFormat:@"%@%@",[[NSString stringWithFormat:@"%@%@%@",user.uid,time,PRIVATE_KEY] md5],PRIVATE_KEY] md5] substringToIndex:10];
    [param setObject:time forKey:@"t"];
    [param setObject:auth forKey:@"auth"];
    MKNetworkOperation *op = [[self createEngine] operationWithPath:@"web/qy_book.php" params:param httpMethod:@"GET"];
    if (!self.downloadChargeArray) {
        _downloadChargeArray = [[NSMutableArray alloc]init];
    }
    [self.downloadChargeArray addObject:op];
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        [self cancelChargeNetworkOperation:completedOperation];
        id result =[completedOperation responseJSON];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
                resultDict(result);
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
        if (![error.localizedDescription isEqualToString:@"下载任务已取消"]) {
            [self cancelChargeNetworkOperation:completedOperation];
        }
        
    }];
    [op setFreezable:YES];
    [[self createEngine] enqueueOperation:op forceReload:YES];

}
#pragma mark 取消一个章节扣费接口的请求
-(void)cancelChargeNetworkOperation:(MKNetworkOperation *)completedOperation{
    for (MKNetworkOperation *op in self.downloadChargeArray) {
        if ([op.url isEqualToString:completedOperation.url]) {
//            [op cancel];
            [self.downloadChargeArray removeObject:op];
            break;
        }
    }
}
#pragma mark 取消所有章节扣费接口的请求
-(void)cancelAllChargeNetworkOperation{
    if (self.downloadChargeArray) {
        for (MKNetworkOperation *op in self.downloadChargeArray) {
            NSDictionary *userInfo = [NSDictionary dictionaryWithObject:@"下载任务已取消"                                                                      forKey:NSLocalizedDescriptionKey];
            NSError *error = [NSError errorWithDomain:NSCocoaErrorDomain code:202 userInfo:userInfo];
            [op operationFailedWithError:error];
            [op cancel];
//            [self.downloadChargeArray removeObject:op];
        }
    }
    [self.downloadChargeArray removeAllObjects];
}
#pragma mark 多章节下载
-(void)downloadChapterTextStr:(NSString *)bookChapters purviewMark:(NSString *)purviewMark Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    //web/qy_book.php?a=download_articleid&purviewMark=as89as7d8asas98d6aas89&chapterids=99997,99998,99999&output=txt&ct=&v=
    if (bookChapters.length<1) {
        errorString(@"章节ID不能为空");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"download_articleid" forKey:@"a"];
    [param setObject:bookChapters forKey:@"chapterids"];
    [param setObject:purviewMark forKey:@"purviewMark"];
    [param setObject:@"iOS" forKey:@"srcid"];
    [param setObject:@"json" forKey:@"output"];
    NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
    [param setObject:currentAppVersion forKey:@"v"];
    [param setObject:@"iOS" forKey:@"ct"];
    [self noTokenGetConnect:param url:@"web/qy_book.php" response:^(NSDictionary *resultDic) {
        NSArray *chapter_list = [[resultDic objectForKey:@"body"] objectForKey:@"chapter_list"];
        if (chapter_list.count<1) {
            errorString(@"章节下载失败");
        }else{
            NSString *articleid = [[resultDic objectForKey:@"body"] objectForKey:@"articleid"];
            for (NSDictionary *dict in chapter_list) {
                BookChapterText *chapterText = [BookChapterText new];
                chapterText.articleid = articleid;
                chapterText.chapterName = [dict objectForKey:@"subhead"];;
                chapterText.chapterTextString = [dict objectForKey:@"text"];
                chapterText.chapterId = [dict objectForKey:@"id"];
                [[ZMYLKDB getLKDBHelper] updateBookChapterText:chapterText];
            }
            resultDict(@{});
        }
        
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 获取订单号
-(void)getProductIdReadPackage:(NSString *)readPackage Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    //web/qy_apple.php?a=get_pay_ordersn&ReadPackage=&uid=&token=&auth=&t=
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"get_pay_ordersn" forKey:@"a"];
    [param setObject:readPackage forKey:@"ReadPackage"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    NSString *time = [NSString stringWithFormat:@"%.f",[ZMYNetWorkAPI currentTime]];
    NSString *auth = [[[NSString stringWithFormat:@"%@%@",[[NSString stringWithFormat:@"%@%@%@",user.uid,time,PRIVATE_KEY] md5],PRIVATE_KEY] md5] substringToIndex:10];
    [param setObject:time forKey:@"t"];
    [param setObject:auth forKey:@"auth"];
    [self noTokenGetConnect:param url:@"web/qy_apple.php" response:^(NSDictionary *resultDic) {
        resultDict([resultDic objectForKey:@"body"]);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 充值接口
-(void)updateYuebi:(RechargeRecord *)recharge Response:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    //web/qy_apple.php?a=add_post_order
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        errorString(@"请先登录");
        return;
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
    [param setObject:currentAppVersion forKey:@"v"];
    [param setObject:@"iOS" forKey:@"ct"];
    NSString *time = [NSString stringWithFormat:@"%.f",[ZMYNetWorkAPI currentTime]];
    NSString *auth = [[[NSString stringWithFormat:@"%@%@",[[NSString stringWithFormat:@"%@%@%@",user.uid,time,PRIVATE_KEY] md5],PRIVATE_KEY] md5] substringToIndex:10];
    [param setObject:time forKey:@"t"];
    [param setObject:auth forKey:@"auth"];
    [param setObject:recharge.rechargeRecordID forKey:@"trade_no"];
    [param setObject:recharge.receiptBASE64 forKey:@"encodeStr"];
    [self noTokenPostConnect:param url:@"web/qy_apple.php?a=add_post_order" response:^(NSDictionary *resultDic) {
        recharge.isUpdateFinesh = YES;
        [[ZMYLKDB getLKDBHelper]updateRechargeRecord:recharge];
        resultDict(resultDic);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 书城
#pragma mark 获取分类项目
-(void)getBookShopTitle{
    //dataapi.yuewen.cc/web/store.php?a=index_bar&ct=ios
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"index_bar" forKey:@"a"];
    [param setObject:@"iOS" forKey:@"ct"];
    [self noTokenGetConnect:param url:@"web/store.php" response:^(NSDictionary *resultDic) {
        NSArray *titleArray = [resultDic objectForKey:@"body"];
        [NSKeyedArchiver archiveRootObject:titleArray toFile:[[PathHelper documentDirectoryPathWithName:@"db"]stringByAppendingPathComponent:@"bookShop"]];
    } error:^(NSString *errorStr) {
        
    }];
}
#pragma mark 获取热门搜索
-(void)searchHotTitleResponse:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    //dataapi.yuewen.cc/web/search.php?a=hot
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"hot" forKey:@"a"];
    [param setObject:@"iOS" forKey:@"ct"];
    [self noTokenGetConnect:param url:@"web/search.php" response:^(NSDictionary *resultDic) {
        NSArray *titleArray = [resultDic objectForKey:@"body"];
        resultArray(titleArray);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 搜索提示
-(void)searchPrompt:(NSString *)searckKey Response:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"so" forKey:@"a"];
    [param setObject:@"1" forKey:@"app"];
    [param setObject:searckKey forKey:@"k"];
    [param setObject:@"iOS" forKey:@"ct"];
//     NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
    [self noTokenGetConnect:param url:@"web/search.php" response:^(NSDictionary *resultDic) {
        NSArray *titleArray = [resultDic objectForKey:@"body"];
        resultArray(titleArray);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 搜索结果
-(void)searchResult:(NSString *)searckKey Response:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"so" forKey:@"a"];
    [param setObject:@"1" forKey:@"app"];
    [param setObject:@"1" forKey:@"detail"];
    [param setObject:searckKey forKey:@"k"];
    [param setObject:@"iOS" forKey:@"ct"];
    //     NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
    [self noTokenGetConnect:param url:@"web/search.php" response:^(NSDictionary *resultDic) {
        NSArray *titleArray = [resultDic objectForKey:@"body"];
        NSMutableArray *bookArray = [NSMutableArray new];
        for (NSDictionary *dict in titleArray) {
            Book *book = [Book getFromSearchDict:dict];
            [bookArray addObject:book];
        }
        resultArray(bookArray);
    } error:^(NSString *errorStr) {
        if ([errorStr isEqualToString:@"可以进行下一步搜索"]) {
            [self searchYiDongResult:searckKey Response:resultArray error:errorString];
        }else if ([errorStr isEqualToString:@"没有搜索结果"]) {
            errorString(@"没有你要找的内容，小编会继续完善相关书籍。查看热门搜索试试吧？");
        }else{
            errorString(errorStr);
        }
    }];
}
#pragma mark 搜索移动基地结果
-(void)searchYiDongResult:(NSString *)searckKey Response:(ResultArray)resultArray error:(MYErrorBlock)errorString{
    //wap.cmread.com/r/p/SearchInterface.jsp?vt=9&kw=%E5%8D%83%E5%B1%B1&ot=1&it=1&st=1&vt=9&page=1
    /*vt=9表示响应格式为数据类型
        kw是搜索关键字
     ot=1表示书籍搜索
     it=1表示搜索全部，0：全部1：图书，2：漫画，3：杂志，4：听书
     st=1表示搜书名，1：书名，2：作者，3：关键字，5：主播
     ssr=3表示排序，0：默认，3：更新时间，8：销量
     page，获取第几页
          */
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"9" forKey:@"vt"];
    [param setObject:@"1" forKey:@"ot"];
    [param setObject:@"1" forKey:@"it"];
    [param setObject:@"3" forKey:@"st"];
    [param setObject:@"3" forKey:@"ssr"];
    [param setObject:@"1" forKey:@"page"];
    [param setObject:searckKey forKey:@"kw"];
    
    [self yiDongChapterConnect:param url:@"r/p/SearchInterface.jsp" response:^(NSDictionary *resultDic) {
        NSArray *titleArray = [resultDic objectForKey:@"SearchResultList"];
        if ([titleArray isKindOfClass:[NSArray class]]) {
            NSMutableArray *bookArray = [NSMutableArray new];
            for (NSDictionary *dict in titleArray) {
                Book *book = [Book getFromYiDongSearchDict:dict];
                [bookArray addObject:book];
            }
            if (bookArray.count<1) {
                errorString(@"没有你要找的内容，小编会继续完善相关书籍。查看热门搜索试试吧？");
            }else{
                resultArray(bookArray);
            }
        } else {
            errorString(@"没有你要找的内容，小编会继续完善相关书籍。查看热门搜索试试吧？");
        }
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 获取奇悠授权id号
-(void)getYiDongFromID:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    //wap.iqiyoo.com/clients/get_third_id/third_name
    [self yiDongConnect:nil url:@"clients/get_third_id/qiyue" response:^(NSDictionary *resultDic) {
        NSString *YiDongFromID = [resultDic objectForKey:@"id"];
        if (YiDongFromID.length>1) {
            [[NSUserDefaults standardUserDefaults]setObject:YiDongFromID forKey:@"YiDongFromID"];
            [[NSUserDefaults standardUserDefaults]synchronize];
            resultDict(resultDic);
        } else {
            errorString(@"没有获取到内容，请稍后再试");
        }
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark 获取移动基地章节内容
-(void)getYiDongChapterText:(Book *)book ChapterID:(NSString *)chapterID ResultBlock:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    //wap.cmread.com/r/380129107/380129955/index.htm?vt=9&cm=M2040002
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"9" forKey:@"vt"];
    NSString *cm = [[NSUserDefaults standardUserDefaults] objectForKey:@"YiDongFromID"];
    NSString *articleid;
    if ([book.articleid hasPrefix:@"qiyou"]) {
        articleid = [book.articleid substringFromIndex:5];
    } else {
        articleid = book.articleid;
    }
    if (cm.length<2) {
        [self getYiDongFromID:^(NSDictionary *resultDic) {
            [param setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"YiDongFromID"] forKey:@"cm"];
            
            [self yiDongChapterConnect:param url:[NSString stringWithFormat:@"r/%@/%@/index.htm",articleid,chapterID] response:^(NSDictionary *resultDic) {
                NSString *chapterTextString = [resultDic objectForKey:@"content"];
                if (chapterTextString.length>50) {
                    BookChapterText *chapterText = [BookChapterText new];
                    chapterText.articleid = book.articleid;
                    chapterText.chapterName = [resultDic objectForKey:@"name"];
                    chapterText.chapterTextString = chapterTextString;
                    chapterText.chapterId = chapterID;
                    [[ZMYLKDB getLKDBHelper] updateBookChapterText:chapterText];
                    resultDict(@{@"BookChapterText":chapterText});
                } else {
                    NSString *loginSubmitUrl = [resultDic objectForKey:@"loginSubmitUrl"];
                    if (loginSubmitUrl.length>10) {
                        resultDict(@{@"loginSubmitUrl":loginSubmitUrl});
                    } else {
                        NSString *orderMsg = [resultDic objectForKey:@"orderMsg"];
                        if (orderMsg) {
                            resultDict(@{@"subscriptionView":resultDic});
                        } else {
                            errorString(@"下载章节失败");
                        }

                    }
                }
            } error:^(NSString *errorStr) {
                errorString(errorStr);
            }];
        } error:^(NSString *errorStr) {
            errorString(errorStr);
        }];
    } else {
        [param setObject:[[NSUserDefaults standardUserDefaults] objectForKey:@"YiDongFromID"] forKey:@"cm"];
        [self yiDongChapterConnect:param url:[NSString stringWithFormat:@"r/%@/%@/index.htm",articleid,chapterID] response:^(NSDictionary *resultDic) {
            NSString *chapterTextString = [resultDic objectForKey:@"content"];
            if (chapterTextString.length>50) {
                BookChapterText *chapterText = [BookChapterText new];
                chapterText.articleid = book.articleid;
                chapterText.chapterName = [resultDic objectForKey:@"name"];
                chapterText.chapterTextString = chapterTextString;
                chapterText.chapterId = chapterID;
                [[ZMYLKDB getLKDBHelper] updateBookChapterText:chapterText];
                resultDict(@{@"BookChapterText":chapterText});
            } else {
                NSString *loginSubmitUrl = [resultDic objectForKey:@"loginSubmitUrl"];
                if (loginSubmitUrl.length>10) {
                    resultDict(@{@"loginSubmitUrl":loginSubmitUrl});
                } else {
                    NSString *orderMsg = [resultDic objectForKey:@"showName"];
                    if (orderMsg) {
                        resultDict(@{@"subscriptionView":resultDic});
                    } else {
                        errorString(@"下载章节失败");
                    }
                    
                }
            }
        } error:^(NSString *errorStr) {
            errorString(errorStr);
        }];
    }
    
}
#pragma mark 移动基地的登录
-(void)getYiDongLogin:(NSDictionary *)param ResultBlock:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    MKNetworkOperation *op = [[self createEngineYiDongChapter] operationWithPath:@"sso/oauth2/login?e_l=9&client_id=cmread-wap&response_type=token"  params:param httpMethod:@"POST" ssl:YES];
    
    op.shouldContinueWithInvalidCertificate=YES;
    [op addCompletionHandler:^(MKNetworkOperation *completedOperation) {
        id result =[self dictionaryWithJsonString:[completedOperation responseString]];
        if ([result isKindOfClass:[NSDictionary class]]) {
            if (![self detectionFormDict:result withURL:completedOperation.url]) {
                errorString(@"系统错误!");
            }else{
                resultDict(result);
            }
        }else{
            errorString(@"系统错误!");
        }
    } errorHandler:^(MKNetworkOperation *completedOperation, NSError *error) {
        errorString(@"网络连接失败!");
    }];
    [[self createEngine] enqueueOperation:op forceReload:YES];
}
#pragma mark 移动基地的订阅扣费
-(void)chargeForYiDongLogin:(NSString *)path ResultBlock:(MYResultBlock)resultDict error:(MYErrorBlock)errorString{
    [self yiDongChapterConnect:nil url:path response:^(NSDictionary *resultDic) {
        resultDict(resultDic);
    } error:^(NSString *errorStr) {
        errorString(errorStr);
    }];
}
#pragma mark - 分享一本书任务完成
-(void)taskFinsh{
    UserAccount *user = [UserAccount currentAccount];
    if (!user) {
        return;
    }
    //web/qy_user.php?a=task_data&uid=&token=&taskname=BookShare&t=
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setObject:@"task_data" forKey:@"a"];
    [param setObject:user.uid forKey:@"uid"];
    [param setObject:user.token forKey:@"token"];
    [param setObject:@"BookShare" forKey:@"taskname"];
    NSString *currentAppVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
    [param setObject:currentAppVersion forKey:@"v"];
    [param setObject:@"iOS" forKey:@"ct"];
    NSString *time = [NSString stringWithFormat:@"%.f",[ZMYNetWorkAPI currentTime]];
    NSString *auth = [[[NSString stringWithFormat:@"%@%@",[[NSString stringWithFormat:@"%@%@%@",user.uid,time,PRIVATE_KEY] md5],PRIVATE_KEY] md5] substringToIndex:10];
    [param setObject:time forKey:@"t"];
    [param setObject:auth forKey:@"auth"];
    [self noTokenGetConnect:param url:@"web/qy_user.php" response:^(NSDictionary *resultDic) {
        
    } error:^(NSString *errorStr) {
        
    }];
}
@end
